package com.sugon.service.impl;

import cn.hutool.core.util.RandomUtil;
import com.sugon.dao.SysKnowTypeDao;
import com.sugon.entity.SysKnowTypeEntity;
import com.sugon.service.SysKnowTypeService;
import com.sugon.utils.Constant;
import com.sugon.utils.ShiroUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * 知识类型Service实现类
 *
 * @author sugon
 * @date 2019-11-27 09:48:04
 */
@Service("sysKnowTypeService")
public class SysKnowTypeServiceImpl implements SysKnowTypeService {
    @Autowired
    private SysKnowTypeDao sysKnowTypeDao;

    @Override
    public Map<String, String> listAll() {
        Map<String, String> knowTypes = new LinkedHashMap<>();
        List<SysKnowTypeEntity> sysKnowTypes = sysKnowTypeDao.queryList(null);
        sysKnowTypes.forEach(sysKnowType -> {
            knowTypes.put(sysKnowType.getId(),sysKnowType.getKonwName());
        });
        return knowTypes;
    }

    @Override
    public SysKnowTypeEntity queryObject(String id) {
        return sysKnowTypeDao.queryObject(id);
    }

    @Override
    public List<SysKnowTypeEntity> queryList(Map<String, Object> map) {
        return sysKnowTypeDao.queryList(map);
    }

    @Override
    public int queryTotal(Map<String, Object> map) {
        return sysKnowTypeDao.queryTotal(map);
    }

    @Override
    public int save(SysKnowTypeEntity sysKnowType) {
        sysKnowType.setId(RandomUtil.randomString(32));
        sysKnowType.setCreateUser(ShiroUtils.getUserId());
        sysKnowType.setCreateDate(new Date());
        sysKnowType.setDelFlag(Constant.IS_NOT_DEL);
        return sysKnowTypeDao.save(sysKnowType);
    }

    @Override
    public int update(SysKnowTypeEntity sysKnowType) {
        sysKnowType.setUpdateUser(ShiroUtils.getUserId());
        sysKnowType.setUpdateDate(new Date());
        return sysKnowTypeDao.update(sysKnowType);
    }

    @Override
    public int delete(String id) {
        return sysKnowTypeDao.delete(id);
    }

    @Override
    public int deleteBatch(String[] ids) {
        return sysKnowTypeDao.deleteBatch(ids);
    }
}
